<script type="text/javascript">
function posts_redicect( category_id ) {
    var url = '<?php echo $html->admin_url('/posts/posts/'); ?>'+category_id;
    window.location = url;
}

function delete_posts() {
    var ids = '';
    $("input[@type=checkbox]:checked").each(function() {
        if (this.value != '') {
              ids = ids + this.value + '|';
        }
    });
    if (ids == '') {
        show_noticemessage('<?php __e('No conversations selected.'); ?>');
    } else {
        $.getJSON('<?php echo $html->admin_url('/posts/ajax_posts/' . $category_id . '/' . $page); ?>/'+ ids + '?time=' + time_now(), function(json_data) {
            if (json_data.deleted_count == 0) {
                results_status = 'deleted_failed';
            } else {
                results_status = 'deleted_done';
            }
            window.location.href='<?php echo $html->admin_url('/posts/posts/' . $category_id . '/' . $page . '/'); ?>' + results_status;
            return true;
            var tablebar_content = $('.tablebar_content').html();
            $('#list').html(json_data.postlist);
            $('.tablebar_content').html(tablebar_content);
            var msg = '';
            if (json_data.count != 0) {
                msg = json_data.count+' <?php __e('conversations have been deleted.'); ?>';
            } else {
                msg = '<?php __e('No conversations selected.'); ?>';
            }
            show_noticemessage(msg);
        });
    }
}

function change_star(post_id) {
    var star_img;
    var img_url;

    $.get('<?php echo $html->admin_url('/posts/ajax_change_star/'); ?>'+ post_id + '?time=' + time_now(), function(data) {
        if (data == 'on') {
            star_img = 'star_on.gif';
        } else {
            star_img = 'star_off.gif';
        }
        $('#star_img_' + post_id).attr({ 
            src: '<?php echo $html->theme_path('img'); ?>/' + star_img
        });
    });
}
</script>

<div id="content">
 <form id="list">
    <table>
      <tr>
        <td colspan="4" class="tablebar"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left"><span class="tablebar_content"><input value="<?=__('Delete')?>" type="button" onclick="delete_posts();">
        <select name="category" id="category" onchange="posts_redicect(this.value);">
        <?php echo $select_list;?>
       </select></span>
            <td align="right"><span class="page_link"><?=$posts->pagelink?></span></td>
          </tr>
        </table></td>
        </tr>
<?php
if(!empty($posts->results)) {
?>
      <tr>
        <th> <input value="" type="checkbox" name="select_all" id="select_all" onclick="mod_allcheckbox_status2( 'post_id[]' , this.checked );"> <?php __e('Title'); ?></th>
        <th><?php __e('Categories'); ?></th>
        <th><?php __e('Author'); ?></th>
        <th><?php __e('When'); ?></th>
      </tr>

<?php
    foreach($posts->results as $post) {
        $star_img = $post->star_status ? 'star_on.gif' : 'star_off.gif';
        if (empty($post->post_title)) {
            $post_title = '(' . __('no title') . ')';
            $style = 'color:#999;';
        } else {
            $post_title = $post->post_title;
            $style = '';
        }
?>
      <tr id="tr_<?php echo $post->id; ?>">
        <td><input value="<?php echo $post->id; ?>" type="checkbox" id="post_id_<?php echo $post->id; ?>" name="post_id[]" onclick="change_allcheckbox_status('post_id[]','select_all');">
        <a id="star<?php echo $post->id; ?>"><?php echo $html->image($star_img,array('id'=>'star_img_' . $post->id, 'onclick'=>"change_star($post->id, $post->star_status)")); ?></a>
        <?php echo $html->admin_link(attribute_escape($post_title), '/post_new/post_new/' . $post->id . '/edit?' . $this_url, array('title'=>__('Edit ') . $post_title, 'style' => $style)); ?></td>
        <td> <?php echo get_category_name($post->category_id) ?> </td>
        <td> <?php echo get_username_by_id($post->poster_id); ?> </td>
        <td> <?php echo time_format($post->post_time); ?></td>
      </tr>
<?php
    }
?>
      <tr>
        <td colspan="4" class="tablebar"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left"><span class="tablebar_content"><input value="<?=__('Delete')?>" type="button" onclick="delete_posts();">
        <select name="category" id="category" onchange="posts_redicect(this.value);">
        <?php echo $select_list;?>
       </select></span>
    </td>
        <td align="right"><span class="page_link"><?=$posts->pagelink?></span></td>
          </tr>
<?php
}else
{
?>
    <tr class="finalrow">
        <td colspan="4" height="40"><span class="new">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php __e('You have no posts in this category!'); ?> </new></td>
    </tr>
<?php
}
?>
        </table></td>
        </tr>
    </table>
  </form> 
</div>
